// const fs = require('fs')
//
// const rs = fs.createReadStream("./test.txt")
// rs.pipe(process.stdout)

// createWriteStream
const fs = require('fs')

const ws = fs.createWriteStream('./test3.txt')

const tid = setInterval(()=>{
    const num = Number.parseInt(Math.random()*10)
    console.log(num)
    if(num<7){
        ws.write(String(num))
    } else {
        clearInterval(tid)
        ws.end()
    }
},200)

ws.on('finish',()=>{
    console.log('done!')
})
